package com.java.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServerB {

	public static void main(String[] args) {
		ServerSocket ss=null;
		Socket s=null;
		PrintWriter pw=null;
		BufferedReader br=null;
		try {
			ss=new ServerSocket(7777);
			int i=1;
			while (true) {
				s = ss.accept();
				br=new BufferedReader(new InputStreamReader(s.getInputStream()));
				String str=br.readLine();
				System.out.println(i+":"+s.getInetAddress()+str);
				pw = new PrintWriter(s.getOutputStream());
				str=str.toUpperCase();
				pw.println(str);
				pw.flush();
				i++;
			}			
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			if(s!=null) try{s.close();} catch(IOException e){}
			if(ss!=null) try{s.close();} catch(IOException e){}
		}
	}

}
